package bishi;

import java.util.Scanner;

/**
 * @Author liuhaoqi
 * @Date 2020/8/24 13:04
 * @Version 1.0
 */
public class Tencent04 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        int ans = arr[0];
        for (int i = 1; i < n; i++) {
            ans += Math.max((arr[i] - arr[i - 1]), 0);
        }
        int result = Math.min(ans, n);
        System.out.println(result);
    }
}
